#!/bin/bash
baseDirForScriptSelf=$(cd "$(dirname "$0")"; pwd)
source ${baseDirForScriptSelf}/source.sh
# 安装LLVM
source ${baseDirForScriptSelf}/proxy.sh
DownLoad_URL=https://repo.huaweicloud.com/harmonyos/compiler/clang/10.0.1-62608/linux/llvm.tar.gz
file_name=`basename ${DownLoad_URL}`
cd ${work_dir}
if [ ! -f "${work_dir}/${file_name}" ];then
    wget –-no-check-certificate "${DownLoad_URL}" >>${baseDirForScriptSelf}/init_run.log 2>&1
    check_line=$((LINENO-1))
    if [ $? -gt 0 ];then
       push_error "${check_line}" "llvm download failed,please check!" "1"
    else
       check_sha256 "${DownLoad_URL}" "${work_dir}/${file_name}"
    fi
fi
if [ -d ~/llvm ];then
    mv ~/llvm ~/llvm_bak_${unix_time}
fi
mkdir ~/llvm
tar -zxvf ${work_dir}/${file_name} -C ~/llvm  >>${baseDirForScriptSelf}/init_run.log 2>&1
BIN_FILE=`find ~/llvm -maxdepth 5 -type l -name 'clang'`
BIN_PATH=`dirname ${BIN_FILE}`
sudo bash -c "echo 'export PATH=${BIN_PATH}:\$PATH'>/etc/profile.d/llvm.sh"
source /etc/profile
source /etc/profile.d/llvm.sh
llvm_version=`clang --version|grep -i OHOS`
if [ $? -gt 0 ];then
    echo  -e "${failed_color},llvm install failed.Please check!"
    exit 1
else
    echo  -e "${success_color},llvm install success.version:${llvm_version}"
fi